{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  汪虎晨\n",
    "+ 学号  0165212"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "class poor(object):\n",
    "    def __init__(family,x1,x2,x3,x4):\n",
    "        family.edu = x1\n",
    "        family.house = x2\n",
    "        family.water = x3\n",
    "        family.nutrition = x4\n",
    "    def assit(family):\n",
    "        sum = 0\n",
    "        if family.edu == 'lack':\n",
    "            sum = sum+1\n",
    "        if family.house == 'lack':\n",
    "            sum = sum+1\n",
    "        if family.water == 'lack':\n",
    "            sum = sum+1\n",
    "        if family.nutrition == 'lack':\n",
    "            sum = sum+1\n",
    "        if sum>2:\n",
    "            print('\\n贫困户')\n",
    "            if family.edu == 'lack':\n",
    "                print(\"需要对义务教育保障进行帮扶\")\n",
    "            if family.house == 'lack':\n",
    "                print(\"需要对住房安全进行帮扶\")\n",
    "            if family.water  == 'lack':\n",
    "                print(\"需要对饮水安全进行帮扶\")\n",
    "            if family.nutrition == 'lack':\n",
    "                print(\"需要对肉蛋奶豆进行帮扶\")\n",
    "        else:\n",
    "            print('\\n非贫困户')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "贫困户\n",
      "需要对义务教育保障进行帮扶\n",
      "需要对住房安全进行帮扶\n",
      "需要对饮水安全进行帮扶\n",
      "需要对肉蛋奶豆进行帮扶\n",
      "\n",
      "贫困户\n",
      "需要对住房安全进行帮扶\n",
      "需要对饮水安全进行帮扶\n",
      "需要对肉蛋奶豆进行帮扶\n",
      "\n",
      "非贫困户\n"
     ]
    }
   ],
   "source": [
    "jiating_1 = poor('lack','lack','lack','lack')\n",
    "jiating_1.assit()\n",
    "\n",
    "jiating_2 = poor('enough','lack','lack','lack')\n",
    "jiating_2.assit()\n",
    "\n",
    "jiating_2 = poor('enough','enough','enough','lack')\n",
    "jiating_2.assit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class stu(object):\n",
    "    def __init__(person,x1,x2,x3):\n",
    "        person.name = x1\n",
    "        person.score = x2\n",
    "        person.sleep = x3\n",
    "    def assess(person,y1 = 90,y2 = 6):\n",
    "        if person.score>y1 and  person.sleep<y2:\n",
    "            print('%s的BMI可能偏大'%person.name)\n",
    "        else:\n",
    "            print('%s的体重正常'%person.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A的体重正常\n",
      "B的BMI可能偏大\n",
      "C的BMI可能偏大\n"
     ]
    }
   ],
   "source": [
    "stu_1 = stu('A',82,7)\n",
    "stu_1.assess()\n",
    "\n",
    "stu_1 = stu('B',92,5)\n",
    "stu_1.assess()\n",
    "\n",
    "stu_1 = stu('C',82,7)\n",
    "stu_1.assess(80,8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class run(stu):\n",
    "    def __init__(person,x1,x2,x3,x4):\n",
    "        super().__init__(x1,x2,x3)\n",
    "        person.runningtime = x4\n",
    "    def assess(person,y1 = 90,y2 = 6):\n",
    "        if person.score>y1 and  person.sleep<y2:\n",
    "            if person.runningtime>30:\n",
    "                print('%s的趋向正常'%person.name)\n",
    "            else:\n",
    "                print('%s的BMI可能偏大'%person.name)\n",
    "        else:\n",
    "            print('%s的体重正常'%person.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A的体重正常\n",
      "B的趋向正常\n",
      "C的BMI可能偏大\n"
     ]
    }
   ],
   "source": [
    "mumber_1 = run('A',82,7,20)\n",
    "mumber_1.assess()\n",
    "\n",
    "mumber_1 = run('B',92,5,40)\n",
    "mumber_1.assess()\n",
    "\n",
    "mumber_1 = run('C',82,7,20)\n",
    "mumber_1.assess(80,8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
